package org.asiainfo.common.translation.core.impl;

import lombok.AllArgsConstructor;
import org.asiainfo.common.core.service.DictService;
import org.asiainfo.common.core.utils.StringUtils;
import org.asiainfo.common.translation.annotation.TranslationType;
import org.asiainfo.common.translation.constant.TransConstant;
import org.asiainfo.common.translation.core.TranslationInterface;

/**
 * 字典翻译实现
 */
@AllArgsConstructor
@TranslationType(type = TransConstant.DICT_TYPE_TO_LABEL)
public class DictTypeTranslationImpl implements TranslationInterface<String> {

    private final DictService dictService;

    /**
     * 根据字典类型和字典值获取字典标签
     *
     * @param key   需要被翻译的键(不为空)
     * @param other 其他参数
     * @return 翻译后的值
     */
    @Override
    public String translation(Object key, String other) {
        if (key instanceof String && StringUtils.isNotBlank(other)) {
            return dictService.getDictLabel(other, key.toString());
        }
        return null;
    }
}
